// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

#pragma once

namespace Store
{
    class StoreData 
        : public Serialization::FabricSerializable
        , public Store::ReplicaActivityTraceComponent<Common::TraceTaskCodes::ReplicatedStore>
    {
    public:
        StoreData(StoreData const & other);
        StoreData & operator = (StoreData const & other);

        virtual ~StoreData();

        __declspec (property(get=get_Type)) std::wstring const & Type;
        virtual std::wstring const & get_Type() const = 0;
        
        __declspec (property(get=get_Key)) std::wstring const & Key;
        virtual std::wstring const & get_Key() const;
        
        __declspec (property(get=get_SequenceNumber)) _int64 SequenceNumber;
        _int64 get_SequenceNumber() const { return sequenceNumber_; }

        void SetSequenceNumber(FABRIC_SEQUENCE_NUMBER);
                
        virtual void WriteTo(__in Common::TextWriter & w, Common::FormatOptions const &) const = 0;

    protected:
        StoreData();
        
        StoreData(Store::ReplicaActivityId const & replicaActivityId);

        StoreData(
            PartitionedReplicaId const & partitionedReplicaId,
            Common::ActivityId const & activityId);

        StoreData(StoreData && other);
        StoreData & operator = (StoreData && other);

        // Gets the key that will be used as unique identifier of the record in the store.
        virtual std::wstring ConstructKey() const = 0;

    private:

        // Key used to uniquely identify the record in the store
        mutable std::wstring cachedKey_;
        
        // Sequence number generated by the replicated store
        _int64 sequenceNumber_;
    };

    typedef std::shared_ptr<StoreData> StoreDataSPtr; 
}
